package com.gaotu.ci.news;

import com.gaotu.ci.support.BasedEntity;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import java.util.Date;
@Entity
@Table(name = "tb_news")
@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class News extends BasedEntity {

    public static final String cacheVersion = "v1.3";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "title")
    private String title;

    @Column(name = "content")
    private String content;

    @Column(name = "status")
    private NewsStatus status;

    @Column(name = "vsn")
    @Version
    private int vsn;

    @Column(name = "update_at")
    private Date updateAt;

    @Column(name = "create_at")
    private Date createAt;

    public static News apply(String title, String content){
        News news = new News();
        news.setTitle(title);
        news.setContent(content);
        return news;
    }

    public boolean isOnline(){
        return NewsStatus.ONLINE.equals(getStatus());
    }

    public boolean isOffline(){
        return NewsStatus.OFFLINE.equals(getStatus());
    }
}
